package treeset;

import java.util.TreeSet;

class Person implements Comparable<Person>{
	int age;
	public Person(int age) {
		super();
		this.age = age;
	}
	@Override
	public int compareTo(Person o) {
		return this.age - o.age;
	}
	@Override
	public String toString() {
		return "Person [age=" + age + "]";
	}
}

public class TreeSetDemo {
	public static void main(String[] args) {
		TreeSet<Integer> set = new TreeSet<>(); 
		set.add(10);
		set.add(20);
		set.add(20);
		set.add(11);
		set.add(89);
		// Comparable? Comparator?
		System.out.println(set);
		
		// TreeSet的类型必须实现Comparable接口
		TreeSet<Person> ps = new TreeSet<>();
		ps.add(new Person(10));
		ps.add(new Person(9));
		ps.add(new Person(19));
		ps.add(new Person(21));
		System.out.println(ps);
	}
}
